import {request} from "./request.js"

export function changePwd(data) {
	return request({
		url: '/api/account/changepassword/',
		method: 'post',
		data: data
	})
}

export function registerAdmin({
	email,
	password,
	password2
}) {
	return request({
		url: '/api/account/staffregister/',
		method: 'post',
		data: {
			email,
			password,
			password2
		}
	})
}

export function register(data) {
	return request({
		url: '/api/account/register/',
		method: 'post',
		data: data
	})
}

export function emailAuth({
	user_id,
	pin
}) {
	return request({
		url: '/api/account/emailauth/',
		method: 'post',
		data: {
			user_id,
			pin
		}
	})
}

export function requestEmailPin({
	user_id
}) {
	return request({
		url: '/api/account/emailpin/',
		method: 'post',
		data: {
			user_id
		}
	})
}

export function googleAuth({
	user_id,
	pin
}) {
	return request({
		url: '/api/account/googleauth/',
		method: 'post',
		data: {
			user_id,
			pin
		}
	})
}

export function login({
	username,
	password
}) {
	return request({
		url: '/api/account/login/',
		method: 'post',
		data: {
			username,
			password
		}
	})
}

export function logOut() {
	const token = uni.getStorageSync('uni_id_token')
	if (!token) {
		return
	}
	return request({
		url: '/api/account/logout/',
		method: 'get'
	})
}

export function resetPage(obj) {
	return request({
		url: '/api/account/reset_page/',
		method: 'post',
		data: obj
	})
}

export function resetPwd(obj) {
	return request({
		url: '/api/account/reset_password/',
		method: 'post',
		data: obj
	})
}

export function getUserList() {
	return request({
		url: '/api/customers/userprofile/',
		method: 'get'
	})
}

export function getUserProfile() {
	return request({
		url: '/api/customers/profile/',
		method: 'get'
	})
}

export function createProfile(obj) {
	return request({
		url: `/api/customers/profile/`,
		method: 'post',
		data: obj
	})
}

export function updateProfile(obj, id = '') {
	return request({
		url: `/api/customers/profile/${id}/`,
		method: 'put',
		data: obj
	})
}

export function summary() {
	return request({
		url: '/api/customers/summary/',
		method: 'get'
	})
}